package five.autoview.adapter;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import java.util.List;

import five.autoview.R;
import five.autoview.activity.BallActivity;
import five.autoview.activity.JianGeXianActivity;
import five.autoview.activity.WenZiActivity;
import five.autoview.myview.BallMoveView;

/**
 * Created by rilintech on 16/6/15.
 */
public class ListAdapter extends BaseAdapter{

    private List<String> list;
    private Activity activity;

    public ListAdapter(List<String> list, Activity activity){
        this.list = list;
        this.activity = activity;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(activity).inflate(R.layout.item, null);
            viewHolder.button = (Button) convertView.findViewById(R.id.button);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.button.setText(list.get(position));
        viewHolder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(position == 0){
                    activity.startActivity(new Intent(activity, WenZiActivity.class));
                }else if(position == 1){
                    activity.startActivity(new Intent(activity, JianGeXianActivity.class));
                }else if(position == 2){
                    activity.startActivity(new Intent(activity, BallActivity.class));
                }
            }
        });

        return convertView;
    }


    class ViewHolder{
        Button button;

    }

}
